<template>
	<view class="">
		<block v-if="value == '0'">
		<checkbox-group>
			<view class="tui-cart-cell  tui-mtop" v-for="(item,index) in dataList" :key="index">
				<tui-swipe-action :params="item">
					<template v-slot:content>
						<view class="tui-goods-item">
							<label class="tui-checkbox" @click="changeSelected(index)">
								<checkbox :checked="item.selected" color="#fff"></checkbox>
							</label>
							<view class="tui-goods-info" style="width: 100%;">
								<view class="tui-goods-title" style="display: inline-block;">
									{{item.name}} 
								</view>
								<view style="float: right;color: #2440b3;margin-right: 20rpx;" @click="edit(item.id)">编辑</view>
							</view>
						</view>
					</template>
				</tui-swipe-action>
			</view>
		</checkbox-group>
		<view class="button" @click="btn(0)">确认添加</view>

		<view class="button" @click="addto(0)">+添加参团联系人</view>
		</block>
		<block v-else-if="value == '2'">
		<checkbox-group>
			<view class="tui-cart-cell  tui-mtop" v-for="(item,index) in dataList" :key="index">
				<tui-swipe-action :params="item">
					<template v-slot:content>
						<view class="tui-goods-item">
							<view class="tui-goods-info" style="width: 100%;">
								<view class="tui-goods-title" style="display: inline-block;">
									{{item.name}} 
								</view>
								<view style="float: right;color: #2440b3;margin-right: 20rpx;" @click="edit(item.id)">编辑</view>
							</view>
						</view>
					</template>
				</tui-swipe-action>
			</view>
		</checkbox-group>	
		<view class="button" @click="addto(0)">+添加参团联系人</view>
		</block>
		<block v-else>
		<checkbox-group>
			<view class="tui-cart-cell  tui-mtop" v-for="(item,index) in PetsList" :key="index">
				<tui-swipe-action :params="item">
					<template v-slot:content>
						<view class="tui-goods-item">
							<label class="tui-checkbox" @click="petsSelected(index)">
								<checkbox :checked="item.selected" color="#fff"></checkbox>
							</label>
							<view class="tui-goods-info">
								<view class="tui-goods-title">
									{{item.title}}
								</view>
							</view>
						</view>
					</template>
				</tui-swipe-action>
			</view>
		</checkbox-group>
		<view class="button" @click="btn(1)">确认添加</view>
		
		<view class="button" @click="addto(1)">+添加参团宠物</view>
		</block>
	</view>
</template>

<script>
	
	var api = require('@/common/api.js')
	export default {

		data() {
			return {
				dataList:[],
				PetsList:[],
				value:'',
				userinfo:[],
				dataList2:[],
				PetsList2:[],
				
			}
		},
		onLoad(options) {
			if(this.tui.isLogin()){
				this.userinfo = uni.getStorageSync("user")
			}else{
				uni.showToast({
					title:"您没有登陆，请先登录",
					icon:"none"
				})
				setTimeout(function(){
					uni.navigateTo({
						url:"/pages/mall-extend/my/my"
					})
				},1000)
			}
			this.value = options.type;
			if(this.value=='0' || this.value=='2'){
				api.get({
					url:"order/personneldata",
					data:{
						user_id:this.userinfo.id,
					},
					success: res => {
				
						this.dataList = res.data
					}
				})
			}else{
				api.get({
					url:"order/petsList",
					data:{
						user_id:this.userinfo.id,
					},
					success: res => {
				
						this.PetsList = res.data
					}
				})
			}


		},
		methods: {

			addto(e){

				uni.navigateTo({
					url: '/pages/mall-extend/address/address?type='+e,
					complete:function(res){
					}//打印错误
				});
			},
			changeSelected(index){

				this.dataList[index].sign = 1;
				this.dataList2[index] = this.dataList[index]
				
			},
			petsSelected(index){
				this.PetsList[index].sign = 1;
				this.PetsList2[index] = this.PetsList[index]
			},
			btn(){

				if(this.value == '0'){
					let pages = getCurrentPages();
					let prevPage = pages[pages.length - 2]; //上一个页面
					prevPage.$vm.lianxi = this.dataList;   //修改上一页data里面的sh参数值为100
					uni.navigateBack({  //uni.navigateTo跳转的返回，默认1为返回上一级
					    delta: 1
					});
				}else{
					let pages = getCurrentPages();
					let prevPage = pages[pages.length - 2]; //上一个页面
					prevPage.$vm.petslist = this.PetsList2;   //修改上一页data里面的sh参数值为100
					uni.navigateBack({  //uni.navigateTo跳转的返回，默认1为返回上一级
					    delta: 1
					});
				}



			},
			edit(info){
				console.log(info);
				api.get({
					url:"order/edit",
					data:{
						id:info,
					},
					success: res => {
				
						uni.navigateTo({
							url: '/pages/edit/edit?query='+encodeURIComponent(JSON.stringify(res.data))
						})
					},
					
				})
			},
			
			
			
			

		}
	}
</script>

<style>

	.button{background-color: rgb(255, 204, 0);
	padding: 20rpx 10rpx;
	width: 60%;
	margin: 40rpx auto;
	border-radius: 20rpx;
	text-align: center;
	}
	
		.tui-cart-cell {
			width: 100%;
			border-radius: 12rpx;
			background: #FFFFFF;
			padding: 40rpx 0;
			overflow: hidden;
		}
	
		.tui-goods-item {
			display: flex;
			padding: 0 30rpx;
			box-sizing: border-box;
		}
	
		.tui-checkbox {
			/* width: 40rpx; */
			padding-right: 30rpx;
			display: flex;
			align-items: center;
		}
	
		/* #ifdef APP-PLUS || MP */
		.tui-checkbox .wx-checkbox-input {
			width: 36rpx;
			height: 36rpx;
			border-radius: 50%;
			margin: 0;
		}
	
		.tui-checkbox .wx-checkbox-input.wx-checkbox-input-checked {
			background: #F82400;
			width: 40rpx;
			height: 40rpx;
			border: none;
		}
	
		/* #endif */
		/* #ifdef H5 */
		>>>.tui-checkbox .uni-checkbox-input {
			width: 36rpx;
			height: 36rpx;
			border-radius: 50% !important;
			margin: 0;
		}
	
		>>>.tui-checkbox .uni-checkbox-input.uni-checkbox-input-checked {
			background: #F82400;
			width: 40rpx;
			height: 40rpx;
			border: none;
		}
</style>
